/**
 * 
 */
package cn.jy.erp.service.impl;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import cn.jy.erp.domain.Component;
import cn.jy.erp.domain.ComponentResult;
import cn.jy.erp.domain.SBPrice;
import cn.jy.erp.domain.ZjkMiddlelibrary;
import cn.jy.erp.domain.ZjkMiddlelibraryQuery;
import cn.jy.erp.domain.ZjkMiddlelibrarydetail;
import cn.jy.erp.domain.ZjkMiddlelibrarydetailQuery;
import cn.jy.erp.mapper.ComponentMapper;
import cn.jy.erp.mapper.ZjkMiddlelibraryMapper;
import cn.jy.erp.mapper.ZjkMiddlelibrarydetailMapper;
import cn.jy.erp.service.ComponertService;

/**
 * @author 刘中斐
 *@date 2018年8月5日 下午6:37:40 
 */
@Service
public class ComponertServiceImpl implements ComponertService{
	@Autowired
	ComponentMapper componentMapper;
	@Autowired
	ZjkMiddlelibrarydetailMapper zjkMiddlelibrarydetailMapper;
	@Autowired
	ZjkMiddlelibraryMapper zjkMiddlelibraryMapper;
	@Override
	public Map<String, Object>  getCost(String TASKBEGINTIME) throws ParseException {
		List<Component> list= componentMapper.getAllData(TASKBEGINTIME);
		Map<String, Object> map=new HashMap<String,Object>();
		List<ComponentResult> result=new ArrayList<ComponentResult>();
		List<ComponentResult> result1=new ArrayList<ComponentResult>();
		List<ComponentResult> result2=new ArrayList<ComponentResult>();
		List<ComponentResult> result3=new ArrayList<ComponentResult>();
		List<ComponentResult> result4=new ArrayList<ComponentResult>();
		List<ComponentResult> result5=new ArrayList<ComponentResult>();
		List<ComponentResult> result6=new ArrayList<ComponentResult>();
		List<ComponentResult> result7=new ArrayList<ComponentResult>();

		double WlCost=0;
		double DLCost=0;
		double RGCost=0;
		long TimeTmp=0;
		double WorkTime=0;
		double SBTime=0;
		double singleton=0;
		double depreciation=0;
		long  spaceTime=0;
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		for (Component component : list) {
			if (component.getTASKBEGINTIME()!=null&&!component.getTASKBEGINTIME().isEmpty()&&component.getTASKENDTIME()!=null&&!component.getTASKENDTIME().isEmpty()) {//人员工作时间,需要算出每个小时的工资
				TimeTmp=sdf.parse(component.getTASKENDTIME()).getTime()-sdf.parse(component.getTASKBEGINTIME()).getTime();
				WorkTime=TimeTmp/1000/60/60;
			}	
			if (component.getHEGEPINZONGKG()!=null&&!component.getHEGEPINZONGKG().isEmpty()&&component.getEXCEPTIONBOXNUMS()!=null&&!component.getEXCEPTIONBOXNUMS().isEmpty()&&component.getEXCEPTIONNUMS()!=null&&!component.getEXCEPTIONNUMS().isEmpty()) {//物料成本
				if (component.getENDTIME()==null||"".equals(component.getENDTIME())) {
					component.setENDTIME("0");
				}
				if (component.getNEEDBOXNUMS()!=null&&!"".equals(component.getNEEDNUMS())) {
					double a=Double.valueOf(component.getHEGEPINZONGKG())+Double.valueOf(component.getENDTIME());
					double b=(Double.valueOf(component.getEXCEPTIONBOXNUMS())+Double.valueOf(component.getEXCEPTIONNUMS()))*0.05;
					String[] array=component.getTYPE().split(" ");
					String c=componentMapper.getDevicePrice(array[0]);
					WlCost=((a+b)*Double.valueOf(c))/Double.valueOf(component.getNEEDNUMS());
				}

			}
			if (component.getKAIJIDIAOBIAODUSHU()!=null&&!component.getKAIJIDIAOBIAODUSHU().isEmpty()&&component.getGUANJIDIANBIAODUSHU()!=null&&!component.getGUANJIDIANBIAODUSHU().isEmpty()&&component.getNEEDNUMS()!=null&&!component.getNEEDNUMS().isEmpty()) {//电量
				DLCost=((Double.valueOf(component.getGUANJIDIANBIAODUSHU())-Double.valueOf(component.getKAIJIDIAOBIAODUSHU()))*0.84)/Double.valueOf(component.getNEEDNUMS());
			}
			if (component.getBEGINADDTIME()!=null&&!component.getBEGINADDTIME().isEmpty()&&component.getGUANJISHIJIAN()!=null&&!component.getGUANJISHIJIAN().isEmpty()) {//设备工作时间
				SBTime=(sdf.parse(component.getGUANJISHIJIAN()).getTime()-sdf.parse(component.getBEGINADDTIME()).getTime())/1000/60/60;
				spaceTime=(sdf.parse(component.getGUANJISHIJIAN()).getTime()-sdf.parse(component.getBEGINADDTIME()).getTime())/1000/60;
			}
			String tsr=componentMapper.getDevicePrice("Ts01");
			String fxr=componentMapper.getDevicePrice("Fx01");
			if (component.getEXCEPTIONUNIT()!=null&&!component.getEXCEPTIONUNIT().isEmpty()) {//调试人工资
				component.setDebuggerWages(String.valueOf(WorkTime*Double.valueOf(tsr)));
			}else {
				component.setDebuggerWages("0");
			}
			if (component.getNEEDER()!=null&&!component.getNEEDER().isEmpty()) {
				component.setCandidateWages(String.valueOf(WorkTime*Double.valueOf(fxr)));
			}else {
				component.setCandidateWages("0");
			}
			if (component.getNEEDNUMS()==null||component.getNEEDNUMS().isEmpty()) {
				component.setNEEDNUMS("0");

			}
			if (component.getNEEDNUMS()!=null&&!"".equals(component.getNEEDNUMS())) {
				RGCost=(Double.valueOf(component.getDebuggerWages())+Double.valueOf(component.getCandidateWages()))/Double.valueOf(component.getNEEDNUMS());
			}

			if ("取样管接头".equals(component.getDETAILNAME())||"内圆锥接头".equals(component.getDETAILNAME())||"三通".equals(component.getDETAILNAME())) {
				ComponentResult cr=new ComponentResult();
				cr.setItemName(component.getDETAILNAME());
				cr.setWorkStartTime(component.getBEGINADDTIME());
				cr.setWorkEndTime(component.getGUANJISHIJIAN());
				cr.setDLCost(DLCost);		
				cr.setRGCost(RGCost);
				cr.setWLCost(WlCost);
				cr.setQualifiedWeight(component.getHEGEPINZONGKG());
				cr.setWaterWeight(component.getENDTIME());
				cr.setSprueWeight(component.getEXCEPTIONBOXNUMS());
				cr.setNotQualifiedWeight(component.getEXCEPTIONNUMS());
				cr.setKAIJIDIAOBIAODUSHU(component.getKAIJIDIAOBIAODUSHU());
				cr.setGUANJIDIANBIAODUSHU(component.getGUANJIDIANBIAODUSHU());
				cr.setDebugger(component.getEXCEPTIONUNIT());
				cr.setCandidate(component.getNEEDER());
				cr.setProductionStartTime(component.getTASKBEGINTIME());
				cr.setProductionEndTime(component.getTASKENDTIME());
				cr.setQualifiedNums(component.getNEEDNUMS());
				cr.setNotQualifiedNums(component.getNEEDBOXNUMS());
				cr.setNewMaterial(component.getPLANNUMS());
				cr.setReturnMaterial(component.getPLANUNIT());
				cr.setMaterialMan(component.getCUSTOMER());
				cr.setDepreciation(depreciation);
				cr.setWorkTime(spaceTime);
				double price=Double.valueOf(componentMapper.getDevicePrice("2lj-01"));
				depreciation=price*SBTime/Double.valueOf(component.getNEEDNUMS());
				singleton=DLCost+RGCost+WlCost+depreciation;
				cr.setTotalCost(singleton);		
				cr.setDepreciation(depreciation);
				result.add(cr);				

			}
			map.put("2lj-01", result);
			map.put("name1", "震雄MKIV型注塑机");
			if ("软接头".equals(component.getDETAILNAME())||"取样管（55mm）".equals(component.getDETAILNAME())||"取样管（75mm）L".equals(component.getDETAILNAME())) {
				ComponentResult cr=new ComponentResult();
				cr.setItemName(component.getDETAILNAME());
				cr.setWorkStartTime(component.getBEGINADDTIME());
				cr.setWorkEndTime(component.getGUANJISHIJIAN());
				cr.setDLCost(DLCost);		
				cr.setRGCost(RGCost);
				cr.setWLCost(WlCost);
				cr.setQualifiedWeight(component.getHEGEPINZONGKG());
				cr.setWaterWeight(component.getENDTIME());
				cr.setSprueWeight(component.getEXCEPTIONBOXNUMS());
				cr.setNotQualifiedWeight(component.getEXCEPTIONNUMS());
				cr.setKAIJIDIAOBIAODUSHU(component.getKAIJIDIAOBIAODUSHU());
				cr.setGUANJIDIANBIAODUSHU(component.getGUANJIDIANBIAODUSHU());
				cr.setDebugger(component.getEXCEPTIONUNIT());
				cr.setCandidate(component.getNEEDER());
				cr.setProductionStartTime(component.getTASKBEGINTIME());
				cr.setProductionEndTime(component.getTASKENDTIME());
				cr.setQualifiedNums(component.getNEEDNUMS());
				cr.setNotQualifiedNums(component.getNEEDBOXNUMS());
				cr.setNewMaterial(component.getPLANNUMS());
				cr.setReturnMaterial(component.getPLANUNIT());
				cr.setMaterialMan(component.getCUSTOMER());
				cr.setDepreciation(depreciation);
				cr.setWorkTime(spaceTime);
				double price=Double.valueOf(componentMapper.getDevicePrice("2lj-01"));
				depreciation=price*SBTime/Double.valueOf(component.getNEEDNUMS());
				singleton=DLCost+RGCost+WlCost+depreciation;
				cr.setTotalCost(singleton);		
				cr.setDepreciation(depreciation);
				result1.add(cr);				

			}
			map.put("2lj-02", result1);	
			map.put("name2", "Demag注塑机");
			if ("单管接头".equals(component.getDETAILNAME())||"双管接头".equals(component.getDETAILNAME())||"穿刺器护套".equals(component.getDETAILNAME())||"穿刺器".equals(component.getDETAILNAME())||"下裙罩".equals(component.getDETAILNAME())||"夹具".equals(component.getDETAILNAME())) {				
				ComponentResult cr=new ComponentResult();
				cr.setItemName(component.getDETAILNAME());
				cr.setWorkStartTime(component.getBEGINADDTIME());
				cr.setWorkEndTime(component.getGUANJISHIJIAN());
				cr.setDLCost(DLCost);		
				cr.setRGCost(RGCost);
				cr.setWLCost(WlCost);
				cr.setQualifiedWeight(component.getHEGEPINZONGKG());
				cr.setWaterWeight(component.getENDTIME());
				cr.setSprueWeight(component.getEXCEPTIONBOXNUMS());
				cr.setNotQualifiedWeight(component.getEXCEPTIONNUMS());
				cr.setKAIJIDIAOBIAODUSHU(component.getKAIJIDIAOBIAODUSHU());
				cr.setGUANJIDIANBIAODUSHU(component.getGUANJIDIANBIAODUSHU());
				cr.setDebugger(component.getEXCEPTIONUNIT());
				cr.setCandidate(component.getNEEDER());
				cr.setProductionStartTime(component.getTASKBEGINTIME());
				cr.setProductionEndTime(component.getTASKENDTIME());
				cr.setQualifiedNums(component.getNEEDNUMS());
				cr.setNotQualifiedNums(component.getNEEDBOXNUMS());
				cr.setNewMaterial(component.getPLANNUMS());
				cr.setReturnMaterial(component.getPLANUNIT());
				cr.setMaterialMan(component.getCUSTOMER());
				cr.setDepreciation(depreciation);
				cr.setWorkTime(spaceTime);
				double price=Double.valueOf(componentMapper.getDevicePrice("2lj-01"));
				depreciation=price*SBTime/Double.valueOf(component.getNEEDNUMS());
				singleton=DLCost+RGCost+WlCost+depreciation;
				cr.setTotalCost(singleton);		
				cr.setDepreciation(depreciation);
				result2.add(cr);				

			}
			map.put("2lj-03", result2);
			map.put("name3", "Demag注塑机");
			if ("上裙罩".equals(component.getDETAILNAME())||"静子头".equals(component.getDETAILNAME())||"压盖".equals(component.getDETAILNAME())) {
				ComponentResult cr=new ComponentResult();
				cr.setItemName(component.getDETAILNAME());
				cr.setWorkStartTime(component.getBEGINADDTIME());
				cr.setWorkEndTime(component.getGUANJISHIJIAN());
				cr.setDLCost(DLCost);		
				cr.setRGCost(RGCost);
				cr.setWLCost(WlCost);
				cr.setQualifiedWeight(component.getHEGEPINZONGKG());
				cr.setWaterWeight(component.getENDTIME());
				cr.setSprueWeight(component.getEXCEPTIONBOXNUMS());
				cr.setNotQualifiedWeight(component.getEXCEPTIONNUMS());
				cr.setKAIJIDIAOBIAODUSHU(component.getKAIJIDIAOBIAODUSHU());
				cr.setGUANJIDIANBIAODUSHU(component.getGUANJIDIANBIAODUSHU());
				cr.setDebugger(component.getEXCEPTIONUNIT());
				cr.setCandidate(component.getNEEDER());
				cr.setProductionStartTime(component.getTASKBEGINTIME());
				cr.setProductionEndTime(component.getTASKENDTIME());
				cr.setQualifiedNums(component.getNEEDNUMS());
				cr.setNotQualifiedNums(component.getNEEDBOXNUMS());
				cr.setNewMaterial(component.getPLANNUMS());
				cr.setReturnMaterial(component.getPLANUNIT());
				cr.setMaterialMan(component.getCUSTOMER());
				cr.setDepreciation(depreciation);
				cr.setWorkTime(spaceTime);
				double price=Double.valueOf(componentMapper.getDevicePrice("2lj-01"));
				depreciation=price*SBTime/Double.valueOf(component.getNEEDNUMS());
				singleton=DLCost+RGCost+WlCost+depreciation;
				cr.setTotalCost(singleton);		
				cr.setDepreciation(depreciation);
				result3.add(cr);				

			}
			map.put("2lj-04", result3);
			map.put("name4", "Demag注塑机");
			if ("壳体".equals(component.getDETAILNAME())) {
				ComponentResult cr=new ComponentResult();
				cr.setItemName(component.getDETAILNAME());
				cr.setWorkStartTime(component.getBEGINADDTIME());
				cr.setWorkEndTime(component.getGUANJISHIJIAN());
				cr.setDLCost(DLCost);		
				cr.setRGCost(RGCost);
				cr.setWLCost(WlCost);
				cr.setQualifiedWeight(component.getHEGEPINZONGKG());
				cr.setWaterWeight(component.getENDTIME());
				cr.setSprueWeight(component.getEXCEPTIONBOXNUMS());
				cr.setNotQualifiedWeight(component.getEXCEPTIONNUMS());
				cr.setKAIJIDIAOBIAODUSHU(component.getKAIJIDIAOBIAODUSHU());
				cr.setGUANJIDIANBIAODUSHU(component.getGUANJIDIANBIAODUSHU());
				cr.setDebugger(component.getEXCEPTIONUNIT());
				cr.setCandidate(component.getNEEDER());
				cr.setProductionStartTime(component.getTASKBEGINTIME());
				cr.setProductionEndTime(component.getTASKENDTIME());
				cr.setQualifiedNums(component.getNEEDNUMS());
				cr.setNotQualifiedNums(component.getNEEDBOXNUMS());
				cr.setNewMaterial(component.getPLANNUMS());
				cr.setReturnMaterial(component.getPLANUNIT());
				cr.setMaterialMan(component.getCUSTOMER());
				cr.setDepreciation(depreciation);
				cr.setWorkTime(spaceTime);
				double price=Double.valueOf(componentMapper.getDevicePrice("2lj-01"));
				depreciation=price*SBTime/Double.valueOf(component.getNEEDNUMS());
				singleton=DLCost+RGCost+WlCost+depreciation;
				cr.setTotalCost(singleton);		
				cr.setDepreciation(depreciation);
				result4.add(cr);				

			}
			map.put("2lj-05", result4);
			map.put("name5", "注吹机");
			if ("开壁管".equals(component.getDETAILNAME())||"软管".equals(component.getDETAILNAME())) {
				ComponentResult cr=new ComponentResult();
				cr.setItemName(component.getDETAILNAME());
				cr.setWorkStartTime(component.getBEGINADDTIME());
				cr.setWorkEndTime(component.getGUANJISHIJIAN());
				cr.setDLCost(DLCost);		
				cr.setRGCost(RGCost);
				cr.setWLCost(WlCost);
				cr.setQualifiedWeight(component.getHEGEPINZONGKG());
				cr.setWaterWeight(component.getENDTIME());
				cr.setSprueWeight(component.getEXCEPTIONBOXNUMS());
				cr.setNotQualifiedWeight(component.getEXCEPTIONNUMS());
				cr.setKAIJIDIAOBIAODUSHU(component.getKAIJIDIAOBIAODUSHU());
				cr.setGUANJIDIANBIAODUSHU(component.getGUANJIDIANBIAODUSHU());
				cr.setDebugger(component.getEXCEPTIONUNIT());
				cr.setCandidate(component.getNEEDER());
				cr.setProductionStartTime(component.getTASKBEGINTIME());
				cr.setProductionEndTime(component.getTASKENDTIME());
				cr.setQualifiedNums(component.getNEEDNUMS());
				cr.setNotQualifiedNums(component.getNEEDBOXNUMS());
				cr.setNewMaterial(component.getPLANNUMS());
				cr.setReturnMaterial(component.getPLANUNIT());
				cr.setMaterialMan(component.getCUSTOMER());
				cr.setDepreciation(depreciation);
				cr.setWorkTime(spaceTime);
				double price=Double.valueOf(componentMapper.getDevicePrice("2lj-01"));
				depreciation=price*SBTime/Double.valueOf(component.getNEEDNUMS());
				singleton=DLCost+RGCost+WlCost+depreciation;
				cr.setTotalCost(singleton);		
				cr.setDepreciation(depreciation);
				result5.add(cr);				

			}
			map.put("2lj-06", result5);
			map.put("name6", "挤塑机");
			if ("袋体".equals(component.getDETAILNAME())||"外套管".equals(component.getDETAILNAME())) {
				ComponentResult cr=new ComponentResult();
				cr.setItemName(component.getDETAILNAME());
				cr.setWorkStartTime(component.getBEGINADDTIME());
				cr.setWorkEndTime(component.getGUANJISHIJIAN());
				cr.setDLCost(DLCost);		
				cr.setRGCost(RGCost);
				cr.setWLCost(WlCost);
				cr.setQualifiedWeight(component.getHEGEPINZONGKG());
				cr.setWaterWeight(component.getENDTIME());
				cr.setSprueWeight(component.getEXCEPTIONBOXNUMS());
				cr.setNotQualifiedWeight(component.getEXCEPTIONNUMS());
				cr.setKAIJIDIAOBIAODUSHU(component.getKAIJIDIAOBIAODUSHU());
				cr.setGUANJIDIANBIAODUSHU(component.getGUANJIDIANBIAODUSHU());
				cr.setDebugger(component.getEXCEPTIONUNIT());
				cr.setCandidate(component.getNEEDER());
				cr.setProductionStartTime(component.getTASKBEGINTIME());
				cr.setProductionEndTime(component.getTASKENDTIME());
				cr.setQualifiedNums(component.getNEEDNUMS());
				cr.setNotQualifiedNums(component.getNEEDBOXNUMS());
				cr.setNewMaterial(component.getPLANNUMS());
				cr.setReturnMaterial(component.getPLANUNIT());
				cr.setMaterialMan(component.getCUSTOMER());
				cr.setDepreciation(depreciation);
				cr.setWorkTime(spaceTime);
				double price=Double.valueOf(componentMapper.getDevicePrice("2lj-01"));
				depreciation=price*SBTime/Double.valueOf(component.getNEEDNUMS());
				singleton=DLCost+RGCost+WlCost+depreciation;
				cr.setTotalCost(singleton);		
				cr.setDepreciation(depreciation);
				result6.add(cr);				

			}
			map.put("2lj-07", result6);
			map.put("name7", "挤塑机");
			//result.clear();
			if ("内套".equals(component.getDETAILNAME())) {
				ComponentResult cr=new ComponentResult();
				cr.setItemName(component.getDETAILNAME());
				cr.setWorkStartTime(component.getBEGINADDTIME());
				cr.setWorkEndTime(component.getGUANJISHIJIAN());
				cr.setDLCost(DLCost);		
				cr.setRGCost(RGCost);
				cr.setWLCost(WlCost);
				cr.setQualifiedWeight(component.getHEGEPINZONGKG());
				cr.setWaterWeight(component.getENDTIME());
				cr.setSprueWeight(component.getEXCEPTIONBOXNUMS());
				cr.setNotQualifiedWeight(component.getEXCEPTIONNUMS());
				cr.setKAIJIDIAOBIAODUSHU(component.getKAIJIDIAOBIAODUSHU());
				cr.setGUANJIDIANBIAODUSHU(component.getGUANJIDIANBIAODUSHU());
				cr.setDebugger(component.getEXCEPTIONUNIT());
				cr.setCandidate(component.getNEEDER());
				cr.setProductionStartTime(component.getTASKBEGINTIME());
				cr.setProductionEndTime(component.getTASKENDTIME());
				cr.setQualifiedNums(component.getNEEDNUMS());
				cr.setNotQualifiedNums(component.getNEEDBOXNUMS());
				cr.setNewMaterial(component.getPLANNUMS());
				cr.setReturnMaterial(component.getPLANUNIT());
				cr.setMaterialMan(component.getCUSTOMER());
				cr.setDepreciation(depreciation);
				cr.setWorkTime(spaceTime);
				double price=Double.valueOf(componentMapper.getDevicePrice("2lj-01"));
				depreciation=price*SBTime/Double.valueOf(component.getNEEDNUMS());
				singleton=DLCost+RGCost+WlCost+depreciation;
				cr.setTotalCost(singleton);		
				cr.setDepreciation(depreciation);
				result7.add(cr);	

			}	
			map.put("2lj-08", result7);
			map.put("name8", "震雄MKIV型注塑机");
			//result.clear();
			//singleton=(WlCost/Double.valueOf(component.getNEEDER()))+(DLCost/SBTime)+(Double.valueOf(component.getEXCEPTIONUNIT())+Double.valueOf(component.getNEEDER()))/Double.valueOf(component.getNEEDNUMS());
			//System.out.println(singleton);
		} 

		System.out.println("请求成功");
		return map;
	}


	@Override
	public List<ComponentResult> getColumnarDate(String detailname) throws Exception {
		List<Component> list= componentMapper.getColumnarDate(detailname);
		Map<String, Object> map=new HashMap<String, Object>();
		List<ComponentResult> result=new ArrayList<ComponentResult>();
		double WlCost=0;
		double DLCost=0;
		long TimeTmp=0;
		double WorkTime=0;
		double SBTime=0;
		double singleton=0;
		double RGCost=0;
		double depreciation=0;
		double taking=0;
		double jjwl=0;
		double zjwl=0;
		String jjwlPrice=null;
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		for (Component component : list) {
			if (component.getTASKBEGINTIME()!=null&&!component.getTASKBEGINTIME().isEmpty()&&component.getTASKENDTIME()!=null&&!component.getTASKENDTIME().isEmpty()) {//人员工作时间,需要算出每个小时的工资
				TimeTmp=sdf.parse(component.getTASKENDTIME()).getTime()-sdf.parse(component.getTASKBEGINTIME()).getTime();
				WorkTime=TimeTmp/1000/60/60;
			}	
			if (component.getHEGEPINZONGKG()!=null&&!component.getHEGEPINZONGKG().isEmpty()&&component.getEXCEPTIONBOXNUMS()!=null&&!component.getEXCEPTIONBOXNUMS().isEmpty()&&component.getEXCEPTIONNUMS()!=null&&!component.getEXCEPTIONNUMS().isEmpty()) {//物料成本
				if (component.getENDTIME()==null||"".equals(component.getENDTIME())) {
					component.setENDTIME("0");
				}
				if (component.getNEEDNUMS()!=null&&!"".equals(component.getNEEDNUMS())) {
					double a=Double.valueOf(component.getHEGEPINZONGKG())+Double.valueOf(component.getENDTIME());
					double b=(Double.valueOf(component.getEXCEPTIONBOXNUMS())+Double.valueOf(component.getEXCEPTIONNUMS()))*0.05;
					String c=componentMapper.getDevicePrice(component.getTYPE());
					WlCost=((a+b)*Double.valueOf(c))/Double.valueOf(component.getNEEDNUMS());
					double f=b*Double.valueOf(c);
					jjwl=f/Double.valueOf(component.getNEEDNUMS());
					BigDecimal bd = new BigDecimal(jjwl); 
					//double df = bd.setScale(5, BigDecimal.ROUND_HALF_UP).doubleValue();
					jjwlPrice=bd.toPlainString();
					System.out.println(bd.toPlainString());
					System.out.println(component.getNEEDNUMS());
					System.out.println(c);
					zjwl=a*Double.valueOf(c)/Double.valueOf(component.getNEEDNUMS());
				}

				//WlCost=((Double.valueOf(component.getHEGEPINZONGKG())+Double.valueOf(component.getENDTIME())+(Double.valueOf(component.getEXCEPTIONBOXNUMS()))+Double.valueOf(component.getEXCEPTIONNUMS())*0.5)*12)/Double.valueOf(component.getNEEDNUMS());
			}
			if (component.getKAIJIDIAOBIAODUSHU()!=null&&!component.getKAIJIDIAOBIAODUSHU().isEmpty()&&component.getGUANJIDIANBIAODUSHU()!=null&&!component.getGUANJIDIANBIAODUSHU().isEmpty()&&component.getNEEDNUMS()!=null&&!component.getNEEDNUMS().isEmpty()) {//电量
				DLCost=((Double.valueOf(component.getGUANJIDIANBIAODUSHU().trim())-Double.valueOf(component.getKAIJIDIAOBIAODUSHU().trim()))*0.84)/Double.valueOf(component.getNEEDNUMS());
			}
			if (component.getBEGINADDTIME()!=null&&!component.getBEGINADDTIME().isEmpty()&&component.getGUANJISHIJIAN()!=null&&!component.getGUANJISHIJIAN().isEmpty()) {//设备工作时间
				SBTime=(sdf.parse(component.getGUANJISHIJIAN()).getTime()-sdf.parse(component.getBEGINADDTIME()).getTime())/1000/60/60;

			}
			String tsr=componentMapper.getDevicePrice("Ts01");
			String fxr=componentMapper.getDevicePrice("Fx01");
			if (component.getEXCEPTIONUNIT()!=null&&!component.getEXCEPTIONUNIT().isEmpty()) {//调试人工资
				component.setDebuggerWages(String.valueOf(WorkTime*Double.valueOf(tsr)));
			}else {
				component.setDebuggerWages("0");
			}
			if (component.getNEEDER()!=null&&!component.getNEEDER().isEmpty()) {
				component.setCandidateWages(String.valueOf(WorkTime*Double.valueOf(fxr)));
			}else {
				component.setCandidateWages("0");
			}
			if (component.getNEEDNUMS()!=null&&!"".equals(component.getNEEDNUMS())&&component.getNEEDBOXNUMS()!=null&&!"".equals(component.getNEEDBOXNUMS())) {
				taking=(WorkTime*60)/(Double.valueOf(component.getNEEDBOXNUMS())+Double.valueOf(component.getNEEDNUMS()));
			}
			ComponentResult cr=new ComponentResult();
			if (component.getNEEDNUMS()!=null&&!"".equals(component.getNEEDNUMS())&&!component.getNEEDNUMS().isEmpty()) {
				System.out.println(component.getTYPENUMS());
				String cString=componentMapper.getDevicePrice("2lj-"+component.getTYPENUMS().substring(5, 7));
				System.out.println(cString);
				double price=Double.valueOf(cString);
				if (component.getNEEDNUMS().isEmpty()) {
					component.setNEEDNUMS("0");
				}
				RGCost=(Double.valueOf(component.getDebuggerWages())+Double.valueOf(component.getCandidateWages()))/Double.valueOf(component.getNEEDNUMS());
				depreciation=price*SBTime/Double.valueOf(component.getNEEDNUMS());
				singleton=DLCost+RGCost+WlCost+depreciation;		
				cr.setItemName(component.getDETAILNAME());
				cr.setWorkStartTime(component.getBEGINADDTIME());
				cr.setWorkEndTime(component.getGUANJISHIJIAN());
				cr.setDLCost(DLCost);		
				cr.setRGCost(RGCost);
				cr.setWLCost(WlCost);
				cr.setTotalCost(singleton);	
				cr.setQualifiedNums(component.getNEEDNUMS());
				cr.setNotQualifiedNums(component.getNEEDBOXNUMS());
				cr.setDepreciation(depreciation);
				cr.setWaterWeight(component.getENDTIME());
				cr.setTaking(taking);
				cr.setIndirectCost(jjwlPrice);
				cr.setDirectCost(zjwl);
				double a=0;
				if (component.getNEEDBOXNUMS()!=null&&!"".equals(component.getNEEDBOXNUMS())) {
					a=Double.valueOf(component.getNEEDBOXNUMS().trim());
				}

				cr.setNotQualifiedPrice(singleton*a);
			}

			result.add(cr);			
		} 

		return result;
	}


	@Override
	public List<String> getPartsName() {

		return componentMapper.getPartsName();
	}



	@Override
	public void updateSbPrice(SBPrice prices) {
		componentMapper.updateSbPrice(prices);
	}



	@Override
	public List<SBPrice> getPrice() {

		return componentMapper.getPrice();
	}

	@Override
	public JSONObject getZJKDetail(String detailname) {


		ZjkMiddlelibrarydetailQuery zjk=new ZjkMiddlelibrarydetailQuery();
		zjk.setFields("b.TASKNUMS,b.ACTUALCOMPLETENUMS,detailname,a.batchnums,type,plannums,planunit,"
				+ "planboxnums,customer,begintime,beginaddtime,picker");
		zjk.createCriteria().andDetailnameEqualTo(detailname);
		//Map<String, Object> map=new HashMap<String, Object>();
		List<ZjkMiddlelibrarydetail> selectAll = zjkMiddlelibrarydetailMapper.selectByExample(zjk);//查询所有
		zjk=new ZjkMiddlelibrarydetailQuery();
		zjk.setFields("distinct a.batchnums");
		zjk.createCriteria().andDetailnameEqualTo(detailname);
		List<ZjkMiddlelibrarydetail> onlyName = zjkMiddlelibrarydetailMapper.selectByExample(zjk);//查询唯一批号

		ZjkMiddlelibraryQuery zjkQuery = new ZjkMiddlelibraryQuery();
		zjkQuery.setFields("batchnums,TASKNUMS");
		zjkQuery.createCriteria().andResourcenameEqualTo(detailname);
		List<ZjkMiddlelibrary> unloadingNums = zjkMiddlelibraryMapper.selectByExample(zjkQuery);



		JSONObject option=new JSONObject();


		JSONObject tooltip=new JSONObject();
		tooltip.put("trigger","axis");
		JSONObject axisPointer=new JSONObject();
		axisPointer.put("type", "shadow");
		tooltip.put("axisPointer", axisPointer);
		option.put("tooltip", tooltip);

		JSONObject legend=new JSONObject();
		JSONArray data=new JSONArray();	
		data.add("入库数量");
		data.add("出库数量");

		legend.put("data",data);

		JSONObject grid=new JSONObject();
		grid.put("left", "10%");
		grid.put("right", "10%");
		grid.put("bottom", "10%");
		grid.put("containLabel", true);


		JSONArray xAxis=new JSONArray();
		JSONArray xdata=new JSONArray();			
		JSONObject object=new JSONObject();
		for (ZjkMiddlelibrary only : unloadingNums) {
			xdata.add(only.getBatchnums());
		}
		object.put("data",xdata);
		object.put("type","category");		
		xAxis.add(object);

		JSONArray yAxis=new JSONArray();
		//JSONArray ydata=new JSONArray();
		JSONObject y=new JSONObject();
		//ydata.add("");
		y.put("type","value");
		yAxis.add(y);

		JSONArray series=new JSONArray();

		JSONArray sdata=new JSONArray();
		JSONObject seriess=new JSONObject();
		for (ZjkMiddlelibrary zjkMiddlelibrary : unloadingNums) {
			sdata.add(zjkMiddlelibrary.getTasknums());
		}
		seriess.put("name", "入库数量");
		seriess.put("type", "bar");
		seriess.put("data", sdata);		
		series.add(seriess);
		Set<String> set=new HashSet<String>();
		for (ZjkMiddlelibrarydetail only : onlyName) {
			List<ZjkMiddlelibrarydetail> list=new ArrayList<ZjkMiddlelibrarydetail>();
			for (ZjkMiddlelibrarydetail all : selectAll) {
				if (only.getBatchnums().equals(all.getBatchnums())) {
					list.add(all);
				}
			}
			if (list.size()>1) {
				for (ZjkMiddlelibrarydetail zjkMiddlelibrarydetail : list) {
					sdata=new JSONArray();
					seriess=new JSONObject();
					sdata.add(zjkMiddlelibrarydetail.getPlannums());
					seriess.put("name", "出库数量");
					seriess.put("type", "bar");
					seriess.put("stack", "广告");
					seriess.put("data", sdata);
					series.add(seriess);
				}
				
			}
			if (list.size()<2) {
				for (ZjkMiddlelibrarydetail zjkMiddlelibrarydetail : list) {
					sdata.add(zjkMiddlelibrarydetail.getPlannums());								
					seriess.put("name", "出库数量");
					seriess.put("type", "bar");
					seriess.put("stack", "广告");
					seriess.put("data", sdata);

				}

			}	

			//System.out.println(sdata);



		}
		//series.add(seriess);
		option.put("legend", legend);
		option.put("grid", grid);
		option.put("xAxis", xAxis);
		option.put("yAxis", yAxis);
		option.put("series",series);


		return option;
	}

	@Override
	public List<ZjkMiddlelibrarydetail> getOnlyDetailName() {
		ZjkMiddlelibrarydetailQuery zjk = new ZjkMiddlelibrarydetailQuery();
		zjk.setFields("distinct detailname");
		List<ZjkMiddlelibrarydetail> selectDetailName = zjkMiddlelibrarydetailMapper.selectByExample(zjk);//查询唯一零件名称
		return selectDetailName;
	}

}
